home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _4E7E2BB32AB14067AE43A93B5DBFF61F < prev    next >
Encoding:
Text File  |  2002-06-14  |  6.4 KB  |  289 lines

  1. // Copyright (C) 2001-2002 Raven Software.
  2. //
  3.  
  4. #include "gt_local.h"
  5.  
  6. #define    ITEM_BRIEFCASE            100
  7.                                 
  8. #define TRIGGER_EXTRACTION        200
  9.  
  10. void    GT_Init        ( void );
  11. void    GT_RunFrame    ( int time );
  12. int        GT_Event    ( int cmd, int time, int arg0, int arg1, int arg2, int arg3, int arg4 );
  13.  
  14. gametypeLocals_t    gametype;
  15.  
  16. typedef struct 
  17. {
  18.     vmCvar_t    *vmCvar;
  19.     char        *cvarName;
  20.     char        *defaultString;
  21.     int            cvarFlags;
  22.     float        mMinValue, mMaxValue;
  23.     int            modificationCount;  // for tracking changes
  24.     qboolean    trackChange;        // track this variable, and announce if changed
  25.     qboolean    teamShader;            // track and if changed, update shader state
  26.  
  27. } cvarTable_t;
  28.  
  29. vmCvar_t    gt_simpleScoring;
  30.  
  31. static cvarTable_t gametypeCvarTable[] = 
  32. {
  33.     { >_simpleScoring,    "gt_simpleScoring",        "0",  CVAR_ARCHIVE, 0.0f, 0.0f, 0, qfalse },
  34.  
  35.     { NULL, NULL, NULL, 0, 0.0f, 0.0f, 0, qfalse },
  36. };
  37.  
  38. /*
  39. ================
  40. vmMain
  41.  
  42. This is the only way control passes into the module.
  43. This must be the very first function compiled into the .q3vm file
  44. ================
  45. */
  46. int vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) 
  47. {
  48.     switch ( command ) 
  49.     {
  50.         case GAMETYPE_INIT:
  51.             GT_Init ( );
  52.             return 0;
  53.  
  54.         case GAMETYPE_START:
  55.             return 0;
  56.  
  57.         case GAMETYPE_RUN_FRAME:
  58.             GT_RunFrame ( arg0 );
  59.             return 0;
  60.  
  61.         case GAMETYPE_EVENT:
  62.             return GT_Event ( arg0, arg1, arg2, arg3, arg4, arg5, arg6 );
  63.     }
  64.  
  65.     return -1;
  66. }
  67.  
  68. /*
  69. =================
  70. GT_RegisterCvars
  71. =================
  72. */
  73. void GT_RegisterCvars( void ) 
  74. {
  75.     cvarTable_t    *cv;
  76.  
  77.     for ( cv = gametypeCvarTable ; cv->cvarName != NULL; cv++ ) 
  78.     {
  79.         trap_Cvar_Register( cv->vmCvar, cv->cvarName, cv->defaultString, cv->cvarFlags, cv->mMinValue, cv->mMaxValue );
  80.         
  81.         if ( cv->vmCvar )
  82.         {
  83.             cv->modificationCount = cv->vmCvar->modificationCount;
  84.         }
  85.     }
  86. }
  87.  
  88. /*
  89. =================
  90. GT_UpdateCvars
  91. =================
  92. */
  93. void GT_UpdateCvars( void ) 
  94. {
  95.     cvarTable_t    *cv;
  96.  
  97.     for ( cv = gametypeCvarTable ; cv->cvarName != NULL; cv++ ) 
  98.     {
  99.         if ( cv->vmCvar ) 
  100.         {
  101.             trap_Cvar_Update( cv->vmCvar );
  102.  
  103.             if ( cv->modificationCount != cv->vmCvar->modificationCount ) 
  104.             {
  105.                 cv->modificationCount = cv->vmCvar->modificationCount;
  106.             }
  107.         }
  108.     }
  109. }
  110.  
  111. /*
  112. ================
  113. GT_Init
  114.  
  115. initializes the gametype by spawning the gametype items and 
  116. preparing them
  117. ================
  118. */
  119. void GT_Init ( void )
  120. {
  121.     gtItemDef_t        itemDef;
  122.     gtTriggerDef_t    triggerDef;
  123.  
  124.     memset ( &gametype, 0, sizeof(gametype) );
  125.  
  126.     // Register all cvars for this gametype
  127.     GT_RegisterCvars ( );
  128.  
  129.     // Register the global sounds
  130.     gametype.caseTakenSound   = trap_Cmd_RegisterSound ( "sound/ctf_flag.mp3" );
  131.     gametype.caseCaptureSound = trap_Cmd_RegisterSound ( "sound/ctf_win.mp3" );
  132.     gametype.caseReturnSound  = trap_Cmd_RegisterSound ( "sound/ctf_return.mp3" );
  133.  
  134.     // Register the items
  135.     memset ( &itemDef, 0, sizeof(itemDef) );
  136.     trap_Cmd_RegisterItem ( ITEM_BRIEFCASE,  "briefcase", &itemDef );
  137.  
  138.     // Register the triggers
  139.     memset ( &triggerDef, 0, sizeof(triggerDef) );
  140.     trap_Cmd_RegisterTrigger ( TRIGGER_EXTRACTION, "briefcase_destination", &triggerDef );
  141. }
  142.  
  143. /*
  144. ================
  145. GT_RunFrame
  146.  
  147. Runs all thinking code for gametype
  148. ================
  149. */
  150. void GT_RunFrame ( int time )
  151. {
  152.     gametype.time = time;
  153.  
  154.     GT_UpdateCvars ( );
  155. }
  156.  
  157. /*
  158. ================
  159. GT_Event
  160.  
  161. Handles all events sent to the gametype
  162. ================
  163. */
  164. int GT_Event ( int cmd, int time, int arg0, int arg1, int arg2, int arg3, int arg4 )
  165. {
  166.     switch ( cmd )
  167.     {
  168.         case GTEV_ITEM_DEFEND:
  169.             if ( !gt_simpleScoring.integer )
  170.             {
  171.                 trap_Cmd_AddClientScore ( arg1, 5 );
  172.             }
  173.             return 0;
  174.  
  175.         case GTEV_ITEM_STUCK:
  176.             trap_Cmd_ResetItem ( ITEM_BRIEFCASE );
  177.             trap_Cmd_TextMessage ( -1, "The Briefcase has returned!" );
  178.             trap_Cmd_StartGlobalSound ( gametype.caseReturnSound );
  179.             return 1;
  180.  
  181.         case GTEV_TEAM_ELIMINATED:
  182.             switch ( arg0 )
  183.             {
  184.                 case TEAM_RED:
  185.                     trap_Cmd_TextMessage ( -1, "Red team eliminated!" );
  186.                     trap_Cmd_AddTeamScore ( TEAM_BLUE, 1 );
  187.                     trap_Cmd_Restart ( 5 );
  188.                     break;
  189.  
  190.                 case TEAM_BLUE:
  191.                     trap_Cmd_TextMessage ( -1, "Blue team eliminated!" );
  192.                     trap_Cmd_AddTeamScore ( TEAM_RED, 1 );
  193.                     trap_Cmd_Restart ( 5 );
  194.                     break;
  195.             }
  196.             break;
  197.  
  198.         case GTEV_TIME_EXPIRED:
  199.             trap_Cmd_TextMessage ( -1, "Red team has defended the briefcase!" );
  200.             trap_Cmd_AddTeamScore ( TEAM_RED, 1 );
  201.             trap_Cmd_Restart ( 5 );
  202.             break;
  203.  
  204.         case GTEV_ITEM_DROPPED:
  205.         {
  206.             char clientname[MAX_QPATH];
  207.             trap_Cmd_GetClientName ( arg1, clientname, MAX_QPATH );
  208.             trap_Cmd_TextMessage ( -1, va("%s has dropped the briefcase!", clientname ) );
  209.             break;
  210.         }
  211.  
  212.         case GTEV_ITEM_TOUCHED:
  213.  
  214.             switch ( arg0 )
  215.             {
  216.                 case ITEM_BRIEFCASE:
  217.                     if ( arg2 == TEAM_BLUE )
  218.                     {
  219.                         char clientname[MAX_QPATH];
  220.                         trap_Cmd_GetClientName ( arg1, clientname, MAX_QPATH );
  221.                         trap_Cmd_TextMessage ( -1, va("%s has taken the briefcase!", clientname ) );
  222.                         trap_Cmd_StartGlobalSound ( gametype.caseTakenSound );
  223.                         trap_Cmd_RadioMessage ( arg1, "got_it" );
  224.  
  225.                         return 1;
  226.                     }
  227.                     break;
  228.             }
  229.  
  230.             return 0;
  231.  
  232.         case GTEV_TRIGGER_TOUCHED:
  233.             switch ( arg0 )
  234.             {
  235.                 case TRIGGER_EXTRACTION:
  236.                     if ( trap_Cmd_DoesClientHaveItem ( arg1, ITEM_BRIEFCASE ) )
  237.                     {
  238.                         char clientname[MAX_QPATH];
  239.                         trap_Cmd_GetClientName ( arg1, clientname, MAX_QPATH );
  240.                         trap_Cmd_TextMessage ( -1, va("%s has escaped with the briefcase!", clientname ) );
  241.                         trap_Cmd_StartGlobalSound ( gametype.caseCaptureSound );
  242.                         trap_Cmd_TakeClientItem ( arg1, ITEM_BRIEFCASE );
  243.                         trap_Cmd_AddTeamScore ( arg2, 1 );
  244.  
  245.                         if ( !gt_simpleScoring.integer )
  246.                         {
  247.                             trap_Cmd_AddClientScore ( arg1, 10 );
  248.                         }
  249.  
  250.                         trap_Cmd_Restart ( 5 );
  251.                     }
  252.                     break;
  253.             }
  254.  
  255.             return 0;
  256.     }
  257.  
  258.     return 0;
  259. }
  260.  
  261. #ifndef GAMETYPE_HARD_LINKED
  262. // this is only here so the functions in q_shared.c and bg_*.c can link (FIXME)
  263.  
  264. void QDECL Com_Error( int level, const char *msg, ... ) 
  265. {
  266.     va_list        argptr;
  267.     char        text[1024];
  268.  
  269.     va_start (argptr, msg);
  270.     vsprintf (text, msg, argptr);
  271.     va_end (argptr);
  272.  
  273.     trap_Error( text );
  274. }
  275.  
  276. void QDECL Com_Printf( const char *msg, ... ) 
  277. {
  278.     va_list        argptr;
  279.     char        text[1024];
  280.  
  281.     va_start (argptr, msg);
  282.     vsprintf (text, msg, argptr);
  283.     va_end (argptr);
  284.  
  285.     trap_Print( text );
  286. }
  287.  
  288. #endif
  289.